<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * Description of member_model
 * 
 * @author Subha Sundar Das (subhasundar.das@gmail.com)
 */
class Member_model extends CI_Model {

    function __construct() {
        parent::__construct();
        log_message('debug', 'Model Initialized');
    }

//-- INSERT NEW MWMBER ---//    
    function append_member($post) {
        if ($post) {
            $this->db->insert('member_master', $post);
            return "<strong>Thank you!</strong> &nbsp; 
                you have successfully Registered. We have send you Login Information to your Email. 
                <strong>Please check your Email and Login.</strong>";
        } else {
            return "<strong>Sorry !</strong> &nbsp; Invalid Operation.";
        }
    }
//-- CHECK MEMBER LOGGED-IN --//
    function check_logedin(){
        if (!$this->session->userdata('mem_email')){
            redirect('member/login');
        }
    }


//-- CHECK MEMBER LOGIN --//
    function check_member($post) {
        if (!$post) {
            return "<strong>Sorry !</strong> &nbsp; Invalid Operation.";
        } else {
            $user = trim($post['email']);
            $pwd = trim($post['password']);
            $sql = "Select * from Member_master where email='$user' and password='$pwd' and status=51";
            $query = $this->db->query($sql);
            $user = $query->row();

            if ($query->num_rows() == 1) {
                $this->session->set_userdata('mem_id', $user->id);
                $this->session->set_userdata('mem_email', $user->email);
                $this->session->set_userdata('mem_password', $user->password);
                $this->session->set_userdata('mem_type', $user->type);
                $this->session->set_userdata('mem_fname', $user->first_name);
                $this->session->set_userdata('mem_lname', $user->last_name);
                $this->session->set_userdata('mem_last_login', $user->last_login);
                $this->session->set_userdata('mem_created_on', $user->created_on);
                //-- Update last login of successfull Login
                $sql = "update member_master set last_login = NOW() where id=$user->id";
                $query = $this->db->query($sql);
                return null;
            }else{
                return "<strong>Sorry !</strong> &nbsp; Invalid Login.";
            }
        }
    }

    
    
    
    
    
    
    
    
//-- END OF MODEL MEMBER --//    
}

?>
